package org.prothliberger.reflect;

import java.lang.reflect.Field;

public class MainCallMethod {

	public static void main(String[] args) throws Exception {
		System.out.println("start");

		Employee vEmployee = new Employee();
		vEmployee.setNom("Rothlisberger");
		vEmployee.setPrenom("Patrick");
		vEmployee.setSexe(Sexe.Masculin);
		vEmployee.setPost("Directeur");
		vEmployee.setSalaire(12000);

		save(vEmployee);

		// Method vGetNomMethod = Employee.class.getMethod("getNom");
		// Object vReturnValue = vGetNomMethod.invoke(vEmployee);
		// System.out.println("return value = " + vReturnValue);
	}

	private static void save(Object aObject) throws Exception {
		Class<?> vClass = aObject.getClass();

		System.out.println("la classe " + vClass
				+ " contient les champs suivants :");
		Field[] vFields = vClass.getDeclaredFields();
		for (Field vField : vFields) {
			vField.setAccessible(true);
			Object vFieldValue = vField.get(aObject);
			System.out.println("champ " + vField.getName() + " = "
					+ vFieldValue);
		}

	}

	private static Object read(Class<?> aClass, int aId) throws Exception {
		Object vValue = aClass.newInstance();
		return vValue;

	}

}
